#include <cmath>
#include "black_scholes_vs.h"
#include "mcnormal_vs.h"

double BlackScholes(int type, double price,
						 double strike, double volatility,
						 double maturity, double risk_free_rate,
						 double dividend_yield)
{

	// double expire_years = maturity/365;

	double d1, d2;

	d1 = log(price/strike) + (risk_free_rate + volatility*volatility/2) * maturity;
	d1 = d1/ (volatility*sqrt(maturity)); 

	d2 = d1 - volatility*sqrt(maturity);

	// type == 1, CALL
	// type == 0, PUT
	if (type == 1) {
		return price*mcnormal_vs(d1) - strike*exp(-risk_free_rate*maturity)*mcnormal_vs(d2);
	} else {
		return strike*exp(-risk_free_rate*maturity)*mcnormal_vs(-d2) - price*mcnormal_vs(-d1);
	} 
}
